#include <dbg.h>

#include <cassert>

using namespace std;

class Solution {
public:
    int peakIndexInMountainArray(vector<int>& arr) {
        int left = -1;
        int right = arr.size();
        while (left + 1 < right) {
            int mid = left + (right - left) / 2;
            if (arr[mid] > arr[mid + 1]) {
                right = mid;
            } else {
                left = mid;
            }
        }
        return right;
    }
};

int main() {
    Solution s;

    vector<int> arr1 = {0, 1, 0};
    vector<int> arr2 = {0, 2, 1, 0};
    vector<int> arr3 = {0, 10, 5, 2};
    vector<int> arr4 = {3, 4, 5, 1};

    assert(s.peakIndexInMountainArray(arr1) == 1);
    assert(s.peakIndexInMountainArray(arr2) == 1);
    assert(s.peakIndexInMountainArray(arr3) == 1);
    assert(s.peakIndexInMountainArray(arr4) == 2);

    return 0;
}